package com.my.study.anno;

import com.my.study.anno.driven.conditional.ConditionConfigure;
import com.my.study.anno.driven.factory.FactoryBeanConfig;
import com.my.study.anno.driven.imports.CustomConfig;
import com.my.study.anno.driven.life.LiftConfig;
import com.my.study.anno.driven.life.Tea;
import com.my.study.anno.driven.property.PersonProperty;
import com.my.study.anno.driven.property.PropertyConfig;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.Environment;

/**
 * @author Carlos
 * @version 1.0
 * @Description 注解驱动测试
 * @date 2021/11/7 19:32
 **/
public class AnnoDrivenTest {

    @Test
    public void conditionTest() {
        ApplicationContext context = new AnnotationConfigApplicationContext(ConditionConfigure.class);

        String[] names = context.getBeanDefinitionNames();
        for (String name : names) {
            System.out.println(name);
        }
    }




    @Test
    public void importTest() {
        ApplicationContext context = new AnnotationConfigApplicationContext(CustomConfig.class);

        String[] names = context.getBeanDefinitionNames();
        for (String name : names) {
            System.out.println(name);
        }
    }

    @Test
    public void factoryBeanTest() {
        ApplicationContext context = new AnnotationConfigApplicationContext(FactoryBeanConfig.class);

        String[] names = context.getBeanDefinitionNames();
        for (String name : names) {
            System.out.println(name);
        }
    }



    @Test
    public void liftTest() {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(LiftConfig.class);
        System.out.println("容器init...");

        context.close();
    }


    @Test
    public void propertyTest() {
        ApplicationContext context = new AnnotationConfigApplicationContext(PropertyConfig.class);

        String[] names = context.getBeanDefinitionNames();
        for (String name : names) {
            System.out.println(name);
        }
        System.out.println("=====");

        Environment environment = context.getEnvironment();
        String property1 = environment.getProperty("person.nickName");
        System.out.println(property1);


        PersonProperty property = context.getBean(PersonProperty.class);
        System.out.println(property);
    }


}
